import Vue from 'vue'
import VueRouter from 'vue-router'
/* import Login from '../components/Login.vue' */
import Home from '../components/Home.vue'
import User from '../components/user/user.vue'
import Book from '../components/books/Book.vue'
import Examine from '../components/books/examine.vue'
import Report from '../components/books/Report.vue'
import UserCounts from '../components/counts/userCounts.vue'
import BookCounts from '../components/counts/bookCounts.vue'
import ElementUI from '../components/ElementUI.vue'
Vue.use(VueRouter)
const routes = [
  {path: '/', redirect: '/home'},
  {path: '/elementUI', component: ElementUI },
  {path: '/home', component: Home, redirect:'/user',
    children:[
      //用户管理
      {path: '/user', component: User},
      //书籍列表
      {path: '/book', component: Book},
      //上传书籍审核
      {path: '/examine', component: Examine},
      //举报书籍受理
      {path: '/report', component: Report},
      //网站用户统计
      {path: '/userCounts', component: UserCounts},
      //网站书籍统计
      {path: '/bookCounts', component: BookCounts},
    ]},
]

const router = new VueRouter({
  routes
})
/* 设置路由导航守卫
    调用形式：
    router.beforeEach((to,from,next) => {})
    参数说明：
      1.to：要访问的路径
      2.from：从哪个路径来
      3.next：请求放行
    策略：1.用户访问/login  放行请求
          2.如果用户没有访问登录页，则校验用户是否登录。校验token
            如果有token，则应该放行，如果没有token，则应该跳转到登录页面
       路由导航守卫，相当于一个拦截器

  */
/* router.beforeEach((to,from,next) => {
    if(to.path === '/login') return next()
    //用户访问的网址不是/login，要获取token
    let token = window.sessionStorage.getBook("token")
    //if(token != null && token.length>0)   简化后如下
    if(token) return next()
    //如果程序执行到这一行，说明token没有数据，则跳转到登录页面
    next("/login")

 }) */




//对外声明路由对象：子组件向父组件传递数据
export default router
